
import 'dart:async';
import 'dart:isolate';

void main() async {
//  Home home = new Home();
//  home.momIsCooking();
//  home.iPlayGame();
//  home.momLetMeBuySoySauce();
//  home.iAgreeToBuy();
//
//  ReceivePort receivePort = ReceivePort();
//  Isolate.spawn(Home.buySoySauce, receivePort.sendPort);
//  var saySauce = await receivePort.first;
//  print(saySauce);



  ReceivePort rcvPort = ReceivePort();
  Isolate.spawn(enter, rcvPort.sendPort);

//  var s = await rcvPort.first;
//  print(s);
    rcvPort.listen(((msg){
    print(msg);
  }));

}

enter(SendPort port){
  Timer.periodic(Duration(seconds: 1), (se){
    port.send('你好好好');
  });
}

class Home {
  void momIsCooking() {
    print("mom is cooking");
  }

  void iPlayGame() {
    Timer.periodic(Duration(seconds: 1), (_) {
      print("game is funning");
    });
  }

  void momLetMeBuySoySauce() {
    print("sweet, can you help to buy a bottle of soy sause, please?");
  }

  void iAgreeToBuy() {
    print("ok,mom. I will buy it");
  }

  static buySoySauce(SendPort sendPort) {
    Timer(Duration(seconds: 5), () {
      sendPort.send("I have bought it");
      sendPort.send("I have bought it");
    });
  }
}